<template>
  <van-tabbar v-model="active" route>
    <van-tabbar-item icon="home-o" to="/home">商城</van-tabbar-item>
    <van-tabbar-item icon="shopping-cart-o" :badge="num" to="/cart">购物车</van-tabbar-item>
    <van-tabbar-item icon="friends-o" to="/mypage">我的</van-tabbar-item>
  </van-tabbar>
</template>
<script>
  export default {
    data: () => ({
      active: 'home',
      num: 0
    }),
    created() {
      this.GetShopingCart()
    },
    methods: {
      async GetShopingCart() {
        try {
          const {
            data
          } = await this.$Api.apiCart.GetShopingCart(JSON.parse(localStorage.getItem('userinfo')).u_id)
          const res = data
          console.log('GetShopingCart',res)
          if (typeof res && !isNaN(res.length)) {
            this.num = res.length
          } else {
            this.num = 0
          }
        } catch (error) {
          // console.log(error)
          console.log(error)
        }
      }
    }
  }

</script>
<style lang="less">
</style>
